//
//  AppDelegate.m
//  WE
//
//  Created by 要帅气的生活 on 15/11/18.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "AppDelegate.h"
#import "MicroMedicalViewController.h"
#import "TheMessageViewController.h"
#import "FoundViewController.h"
#import "MineViewController.h"
//#import "BNCoreServices.h"
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WXApi.h"
#import "WeiboApi.h"
#import "WeiboSDK.h"
#import "WXApi.h"
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    self.tab = [[UITabBarController alloc] init];
    [self initShareSDK];
   // _mapManager = [[BMKMapManager alloc]init];
    // 如果要关注网络及授权验证事件，请设定     generalDelegate参数
//    BOOL ret = [_mapManager start:@"fxtNiwOtgGPN1YPGnINcNGzs"  generalDelegate:self];
//    if (!ret) {
//        NSLog(@"manager start failed!");
//    }
    // Add the navigation controller's view to the window and display.
    //初始化导航SDK
   // [BNCoreServices_Instance initServices:@"fxtNiwOtgGPN1YPGnINcNGzs"];
   // [BNCoreServices_Instance startServicesAsyn:nil fail:nil];
    
    
    MicroMedicalViewController *home = [[MicroMedicalViewController alloc] init];
   // UINavigationController *homeNavi = [[UINavigationController alloc] initWithRootViewController:home];
    home.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"微医" image:[UIImage imageNamed:@"weiyi1.png"] selectedImage:[UIImage imageNamed:@"weiyi2.png"]];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
    TheMessageViewController *property = [[TheMessageViewController alloc] init];
   // UINavigationController *propertyNavi = [[UINavigationController alloc] initWithRootViewController:property];
    property.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"消息" image:[UIImage imageNamed:@"xiaoxi1.png"] selectedImage:[UIImage imageNamed:@"xiaoxi2.png"]];
    
    FoundViewController *client = [[FoundViewController alloc] init];
   // UINavigationController *clientNavi = [[UINavigationController alloc] initWithRootViewController:client];
    client.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"faxian1.png"] selectedImage:[UIImage imageNamed:@"faxian2.png"]];
    
    MineViewController *mine = [[MineViewController alloc] init];
   // UINavigationController *mineNavi = [[UINavigationController alloc] initWithRootViewController:mine];
    mine.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"wode1.png"] selectedImage:[UIImage imageNamed:@"wode2.png"]];
    
    self.tab = [[UITabBarController alloc] init];
    _tab.viewControllers = @[home,property,client,mine];
    /* tabBar背景颜色 */
    //_tab.tabBar.barTintColor = [UIColor grayColor];
    //_tab.tabBar.tintColor = [UIColor blueColor];
    
    _naVC = [[UINavigationController alloc] initWithRootViewController:_tab];
    [_naVC.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:17],
       NSForegroundColorAttributeName:[UIColor blackColor]}];
    //    naVC.navigationBar.hidden = YES;
    _naVC.navigationBar.hidden = YES;
    _naVC.navigationBar.translucent = YES;
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"dayOrNight"];
        NSLog(@"第一次启动");
        /*如果是第一次启动的话,使用`````(用户引导页面) 作为根视图*/
        //        _tab.viewControllers = @[homeNavi,propertyNavi,clientNavi,wealthNavi,mineNavi];
        
        self.window.rootViewController = [[ViewController alloc] init];
        
    }  else{
        
//        MFJNight *night = [MFJNight defaultNight];
//        night.nightKey = [[NSUserDefaults standardUserDefaults] boolForKey:@"dayOrNight"];
//        NSLog(@"%d",[[NSUserDefaults standardUserDefaults] boolForKey:@"dayOrNight"]);
        self.window.rootViewController = _naVC;
    }
    
//    naVC.navigationBar.backgroundColor = [UIColor whiteColor];
//    self.window.rootViewController = _naVC;
//        self.window.rootViewController = self.tab;
    
    return YES;
}
- (void)initShareSDK
{
    [ShareSDK registerApp:@"c23b281133e8"]; //字符串是你的ShareSDK的AppKey App Secret  f3c59e0b90d45fd319c38e62ae65ce14
    
    //添加QQ应用  注册网址  http://mobile.qq.com/api/
    [ShareSDK connectQQWithQZoneAppKey:@"1104762759"
                     qqApiInterfaceCls:[QQApiInterface class]
                       tencentOAuthCls:[TencentOAuth class]];
//    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"1104762759"
                           appSecret:@"aPld3r5vFW5et6s8"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    //添加新浪微博应用 注册网址 http://open.weibo.com
//    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
//                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
//                             redirectUri:@"http://www.sharesdk.cn"];
    //添加微信应用 注册网址 http://open.weixin.qq.com
    [ShareSDK connectWeChatWithAppId:@"wxd2283c53f5d6b7fa"
                           wechatCls:[WXApi class]];
      [ShareSDK ssoEnabled:YES];
}
- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options
{
    return [ShareSDK handleOpenURL:url wxDelegate:self];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)onGetNetworkState:(int)iError{
    if (0==iError) {
        NSLog(@"联网成功");
    }else {
        NSLog(@"%d",iError);
    }
}


- (void)onGetPermissionState:(int)iError{
    if (0 == iError) {
        NSLog(@"授权成功");
    }else {
         NSLog(@"授权失败");
    }
}

@end
